package com.groupbuying.payproducer.payCenterStrategy;

import com.groupbuying.payproducer.constants.PayCenterTypeConstants;
import com.groupbuying.payproducer.utils.SpringBeanUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付策略创建工厂
 *
 * @Author Vincentxin
 * @Date 2019-05-20
 */
public class PayStrategyFactory {
    private static PayStrategyFactory factory = new PayStrategyFactory();

    private PayStrategyFactory() {
    }

    private static Map strategyMap = new HashMap<>();

    static {
        //支付方式与支付渠道做组合
        strategyMap.put(PayCenterTypeConstants.NATIVEWECHATPAY.getValue(), SpringBeanUtil.getBean("nativeWeChatPayStrategy"));
        strategyMap.put(PayCenterTypeConstants.NATIVEALIPAY.getValue(), SpringBeanUtil.getBean("nativeAliPayStrategy"));
        //原生通道下的积分和余额支付（方便处理，实际指向平台的积分和余额处理）
        strategyMap.put(PayCenterTypeConstants.NATIVEBALANCE.getValue(), SpringBeanUtil.getBean("platFormBalancePayStrategy"));
        strategyMap.put(PayCenterTypeConstants.NATIVECURRENCY.getValue(), SpringBeanUtil.getBean("platFormCurrencyPayStrategy"));
        strategyMap.put(PayCenterTypeConstants.YSWECHATPAY.getValue(), SpringBeanUtil.getBean("ysWeChatPayStrategy"));
        strategyMap.put(PayCenterTypeConstants.YSALIPAY.getValue(), SpringBeanUtil.getBean("ysAliPayStrategy"));
        //银盛通道下的积分和余额支付（方便处理，实际指向平台的积分和余额处理）
        strategyMap.put(PayCenterTypeConstants.YSBALANCE.getValue(), SpringBeanUtil.getBean("platFormBalancePayStrategy"));
        strategyMap.put(PayCenterTypeConstants.YSCURRENCY.getValue(), SpringBeanUtil.getBean("platFormCurrencyPayStrategy"));

        strategyMap.put(PayCenterTypeConstants.PLATFORMBALANCE.getValue(), SpringBeanUtil.getBean("platFormBalancePayStrategy"));
        strategyMap.put(PayCenterTypeConstants.PLATFORMCURRENCY.getValue(), SpringBeanUtil.getBean("platFormCurrencyPayStrategy"));
    }

    public PayStrategy creator(String type) {
        return (PayStrategy) strategyMap.get(type);
    }

    public static PayStrategyFactory getInstance() {
        return factory;
    }
}
